<?php

namespace app\api\model;

use think\facade\Cache;
use think\Model;

/**
 * 地区数据模型.
 */
class QuesSubject extends \app\common\model\BaseModel
{
    protected $connection = 'mysql2';
    protected $name = 'subject';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性


    public function __construct(array $data = [])
    {
        parent::__construct($data);

    }


    public function getList($where, $size = 12, $field = '*', $order = 'id desc')
    {
        $list = $this->where(function ($query) use ($where) {
            if (isset($where['category_id']) && $where['category_id']) {
                $query->where('category_id', 'like', '%' . $where['category_id'] . '%');
            }
            if (isset($where['subject_ids']) && $where['subject_ids']) {
                $query->where('id', 'in', $where['subject_ids']);
            }
            if (isset($where['keywords']) && $where['keywords']) {
                $query->where('name', "like", "%{$where['keywords']}%");
            }
        })
            ->with([])
            ->field($field)
            ->order($order)
            ->paginate($size);
        //$list->each(function ($item) {
        //});
        return $list->toArray();

    }


}
